<?php
namespace app\wechat\controller;
use app\api\service\MemberMoney;
use app\api\service\MemberFundAccount;

class DWallet extends WCommon
{
    // 用户钱包首页
    public function index()
    {
        $id = session('member_id');
        // 用户余额
        $money = db('dealer')->where('member_id', $id)->value('money');

        // 获取用户银行卡列表
        $bank_num = db('member_fund_account')->where('member_id', $id)->count();

        $this->assign('data',[
            'money' => $money,
            'bank_num' => $bank_num
        ]);
        return view();
    }

    // 交易明细页面
    public function detail() {
        if (request()->isAjax()) {
            $param['member_id'] = session('member_id');
            $param['type'] = 2;
            $data = MemberMoney::member_money_bill($param);
            return $data;
        }
        return view();
    }

    // 银行卡列表页面
    public function banks() {
        $param['member_id'] = session('member_id');
        $banks = MemberFundAccount::get_member_fund_account($param);
        $this->assign('banks', $banks['data']);
        return view();
    }

    // 添加银行卡列表页面
    public function add_bank() {
        if (request()->isPost()) {
            $param = [
                'member_id' => session('member_id'),
                'type' => input('param.type'),
                'account' => input('param.account'),
                'phone' => input('param.phone'),
                'householder' => input('param.householder'),
                'id_card' => input('param.id_card')
            ];
            $data = MemberFundAccount::save_member_fund_account($param);
        } else {
            return view();
        }
    }

    // 充值
    public function recharge() {
        return view();
    }
}
